import React from 'react'
import PropTypes from 'prop-types'
import { Row, Col, Card, Button ,Table} from 'antd'
import { routerRedux,Link } from 'dva/router'
import styles from './Container.less'
import { connect } from 'dva'




const EditorPage = ({ location, dispatch, testResults, loading }) =>{
  const { list} = testResults


  const colProps = {
    lg: 24,
    md: 24,
  }




  const columns = [
   {
    title: '测试结果ID',
    dataIndex: 'testresult_ID',
    key: 'testresult_ID',
  }, {
    title: '产品名称',
    dataIndex: 'product_name',
    key: 'product_name',
  }, {
      title: '版本号',
      dataIndex: 'release',
      key: 'release',
  }, {
    title: '测试计划名称',
    dataIndex: 'plan_name',
    key: 'plan_name',
  }, {
    title: '机器IP',
    dataIndex: 'ip',
    key: 'ip',
    render: (text,record) => {
      return <span>服务机IP：{record.sut_ip}<br/>测试机IP：{record.testhost_ip}</span>
    },
  }, {
    title: '浏览器',
    dataIndex: 'browser',
    key: 'browser',
  }, {
    title: '套件名称',
    dataIndex: 'suite_name',
    key: 'suite_name',
  }, {
      title: '套件测试时间',
      dataIndex: 'time',
      key: 'time',
      render: (text,record) => {
        return <span>开始时间：{record.starttime}<br/>结束时间：{record.endtime}<br/>执行时间：{record.executetime}</span>
      },
  },{
    title: '套件测试结果',
    dataIndex: 'result',
    key: 'result',
      render: (text,record) => {
        return <span><b>成功：{record.passnum}</b><br/><b className={record.failnum>0?styles.red:''}>失败：{record.failnum}</b><br/><b className={record.errornum>0?styles.red:''}>错误：{record.errornum}</b></span>
      },
  },{
      title: '套件测试报告',
      dataIndex: 'report',
      key: 'report',
      render: (text,record) => {
        return <a href={record.report_path} target="_blank">查看报告</a>
      },
    }];

  const toAllResult=()=>{

    dispatch(routerRedux.push({
      pathname: '/testResult',

    }))
  }

  return (
    <div className="content-inner">

      <Row gutter={32}>
        <Col span={24} style={{marginBottom:'10'}}><Button onClick={toAllResult}>返回所有结果</Button></Col>
        <Col span={24}>

          <Table dataSource={list} columns={columns} pagination={false}/>
        </Col>

      </Row>

    </div>
  )

}
EditorPage.propTypes = {
  testResults: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object,
}

export default connect(({ testResults, loading }) => ({ testResults, loading }))(EditorPage)
